//
//  RootInfo.m
//  Trading365
//
//  Created by yifei tong on 11-12-15.
//  Copyright (c) 2011年 dhc. All rights reserved.
//

#import "RootInfo.h"
#import "ProductList.h"
#import "CustomerList.h"
#import "ChanceList.h"

#import "GUID.h"
#import "LoginView.h"
#import "QuotationList.h"
#import "QuotationInfo.h"
#import "QuotationAdd.h"


@implementation RootInfo
@synthesize table;
@synthesize InfoListTitle;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc
{
    [table release];
    [InfoListTitle release];
    [super dealloc];
}

#pragma mark - View lifecycle


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"信息";
    [self.view setBackgroundColor:BACKGROUND_COLOR];
    self.navigationController.navigationBar.tintColor = NAVIGATION_BAR_COLOR;
    
    UIImage* imageBar = [UIImage imageNamed:PIC_MAIL_TOP_BAR];
    [self.navigationController setNavigationBarHidden:NO];

    NSString* devVersion = [[UIDevice currentDevice] systemVersion];
    if ([devVersion compare:@"4.3.3"] == 0)
    {
        [self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)];
        [self.navigationController.navigationBar setTintColor:NAVIGATION_BAR_COLOR];
    }else
    {
        [self.navigationController.navigationBar setBackgroundImage:imageBar forBarMetrics:UIBarMetricsDefault];
    }
    if ([[Session share] isChance] == YES){
        NSArray *title_array = [[NSArray alloc] initWithObjects:@"客户信息",@"产品信息",@"报价信息",@"商机信息",nil];
        self.InfoListTitle = title_array; 
        [title_array release];
    }else{ 
        NSArray *title_array1 = [[NSArray alloc] initWithObjects:@"客户信息",@"产品信息",@"报价信息",nil];
        self.InfoListTitle = title_array1; 
        [title_array1 release];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    if ([[Session share] isChance] == YES){
        NSArray *title_array = [[NSArray alloc] initWithObjects:@"客户信息",@"产品信息",@"报价信息",@"商机信息",nil];
        self.InfoListTitle = title_array; 
        [title_array release];
    }else{ 
        NSArray *title_array1 = [[NSArray alloc] initWithObjects:@"客户信息",@"产品信息",@"报价信息",nil];
        self.InfoListTitle = title_array1; 
        [title_array1 release];
    }   
    [self.table reloadData];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - table view

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.InfoListTitle count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = (UITableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier: CellIdentifier] autorelease];
    }
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView.backgroundColor = [UIColor clearColor];
    
    NSString* text = @"";
    if (indexPath.row < [self.InfoListTitle count]) 
    {
        text = [self.InfoListTitle objectAtIndex:indexPath.row];
    }
    cell.textLabel.text = text;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row=indexPath.row;
    
    //Customer
    if (row == 0){
        
        CustomerList *customerlist = [[CustomerList alloc] init];
        [self.navigationController pushViewController:customerlist animated:YES];
        [customerlist release];
    }

    //Product
    if (row == 1){
        ProductList *productlist = [[ProductList alloc] init];
        [self.navigationController pushViewController:productlist animated:YES];
        [productlist release];
    }
    
    //QuotationList
    if (row == 2){
        QuotationList *quotlist = [[QuotationList alloc] init];
//        QuotationAdd *quotlist = [[QuotationAdd alloc] init];
        [self.navigationController pushViewController:quotlist animated:YES];
        [quotlist release];
    }
    
    //ChanceList
    if (row == 3){
        ChanceList *chancelist = [[ChanceList alloc] init];
        [self.navigationController pushViewController:chancelist animated:YES];
        [chancelist release];
    }

}

@end
